<template>
    <div class="main">
        <ul class="todo-list">
            <li v-for="item in list" :key="item.id" :class="{ completed: item.done }">
                <div class="view">
                    <input class="toggle" type="checkbox" v-model="item.done" />
                    <label>{{ item.name }}</label>
                    <button class="destory" @click="delTodo(item.id)">删除</button>
                </div>
            </li>
        </ul>
    </div>

</template>

<script setup>
const  props=defineProps(['list'])
const emit = defineEmits(['delTodo']) 

const delTodo = id => { 
    id && emit('delToDo', id) 
 } // 触发事件 

const delToDo = id => { 
    list.value = list.value.filter(item => item.id !== id) 
    } 


</script>

<style scoped>
.main {
  position: relative;
  z-index: 2;
  border-top: 1px solid #e6e6e6;
}
.todo-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.todo-list li {
  position: relative;
  font-size: 24px;
  border-bottom: 1px solid #ededed;
  background: #fff;
}
.todo-list li:last-child {
  border-bottom: none;
}
.todo-list li.completed label {
  color: var(--completed-color);
  text-decoration: line-through;
}
.view {
  display: flex;
  align-items: center;
  padding: 16px;
}
.toggle {
  text-align: center;
  width: 40px;
  height: auto;
  position: absolute;
  top: 10px;
  bottom: 0;
  margin: auto 0;
  border: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.toggle::after {
  content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="40" fill="none" stroke="%23ededed" stroke-width="3"/></svg>');
}
.toggle:checked::after {
  content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="40" fill="none" stroke="%23bddad5" stroke-width="3"/><path fill="%235dc2af" d="M72 25L42 71 27 56l-4 4 20 20 34-52z"/></svg>');
}
.todo-list label {
  word-break: break-all;
  padding: 15px 15px 15px 60px;
  display: block;
  line-height: 1.2;
  transition: color 0.4s;
  flex: 1;
}
.destroy {
  display: none;
  position: absolute;
  top: 0;
  right: 10px;
  bottom: 0;
  width: 40px;
  height: 40px;
  margin: auto 0;
  font-size: 30px;
  color: var(--destroy-hover);
  margin-bottom: 11px;
  transition: color 0.2s ease-out;
  border: none;
  background: none;
  cursor: pointer;
}
.destroy::after {
  content: '×';
}
.todo-list li:hover .destroy {
  display: block;
}
.destroy:hover {
  color: #af5b5e;
}
</style>